package cn.itcast.tanhua.mytanhuaserver.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.itcast.tanhua.mytanhuadubbointerface.api.HuanXinApi;
import cn.itcast.tanhua.mytanhuaserver.service.HuanXinService;
import cn.itcast.tanhua.pojo.HuanXinUser;
import cn.itcast.tanhua.pojo.User;
import cn.itcast.tanhua.utils.UserThreadLocal;
import cn.itcast.tanhua.vo.HuanXinUserVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

/**
 * @author 郭文亮
 * @since 2021/12/4 9:35
 */
@Service
public class HuanXinServiceImpl implements HuanXinService {

    @Reference
    private HuanXinApi huanXinApi;

    @Override
    public HuanXinUserVo queryHuanXinUser() {
        User user = UserThreadLocal.get();
        //通过dubbo服务查询环信用户
        HuanXinUser huanXinUser = this.huanXinApi.queryHuanXinUser(user.getId());
        if (ObjectUtil.isNotEmpty(huanXinUser)) {
            return new HuanXinUserVo(huanXinUser.getUsername(), huanXinUser.getPassword());
        }
        return null;
    }
}
